package jsyf.oa.web.salary;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.salary.SalaryMainFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Maqiuqiu on 2018/11/19.
 */
@Api(value = "工资表接口", description = "工资表接口")
@Controller
@RequestMapping("/salaryMain")
public class SalaryMainController {
    @Resource
    private SalaryMainFacade salaryMainFacade;

    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "添加工资条",
            notes = "添加工资条",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData",value = "",dataType = "String", paramType = "body")
    public void save(HttpServletResponse response, @RequestBody String jsonData) {
        String resultId = this.salaryMainFacade.save(jsonData);
        String result = "";
        if ("".equals(resultId)) {
            result = BaseUtils.errorrRespond("服务器错误");
        } else {
            JSONObject obj = new JSONObject();
            obj.put("id", resultId);
            result = BaseUtils.succsessObjRespond(obj);
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    @RequestMapping(value = "/delById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "删除工资条",
            notes = "删除工资条",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData",value = "{id:''}",dataType = "String", paramType = "body")
    public void delById(HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.salaryMainFacade.delById(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("isOk", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }
    @ResponseBody
    @RequestMapping(value = "/getListInfo.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取列表信息",
            notes = "获取列表信息",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'dateTime':''}", dataType = "String", paramType = "body")
    public void getListInfo(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = salaryMainFacade.getList(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));

    }


}
